<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>修改资源_资源共享平台</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
</head>
<body>
<div style="padding: 20px">
   	<span class="layui-breadcrumb">
        <a>首页</a>
        <a>资源管理</a>
        <a><cite>资源修改</cite></a>
	</span>
    <div style="padding-top: 20px;">
        <form class="layui-form" method="post">
            <input type="hidden" name="id" th:value="${res.id}" />
            <div class="layui-form-item">
                <label class="layui-form-label">资源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="name" th:value="${res.name}" autocomplete="off" placeholder="请输入资源名称" class="layui-input" lay-verify="required" lay-reqText="请输入资源名称" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">资源类别：</label>
                <div class="layui-input-inline">
                    <select name="resType.id" lay-verify="required" lay-reqText="请选择资源类别">
                        <option value="">请选择资源类别</option>
                        <option th:each="resType:${application.allResTypeList}" th:value="${resType.id}" th:text="${resType.name}" th:selected="${resType.id==res.resType.id}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">资源描述：</label>
                <div class="layui-input-block">
                    <textarea id="content" name="content" style="display: none;" th:utext="${res.content}"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">分享资源：</label>
                    <div class="layui-input-inline" style="width: 400px">
                        <input type="text" name="downloadUrl" th:value="${res.downloadUrl}" autocomplete="off" placeholder="请输入百度云分享地址" class="layui-input" lay-verify="url" lay-reqText="请输入百度云分享地址" />
                    </div>
                    <div class="layui-input-inline" style="width: 100px">
                        <input type="text" name="downloadPass" th:value="${res.downloadPass}" autocomplete="off" placeholder="请输入密码" class="layui-input" lay-verify="required" lay-reqText="请输入密码" />
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">积分设置：</label>
                <div class="layui-input-inline" style="width: 120px">
                    <select name="points" th:field="*{res.points}" lay-verify="required" lay-reqText="请选择积分">
                        <option value="">请选择积分</option>
                        <option value="0">0个积分</option>
                        <option value="1">1个积分</option>
                        <option value="2">2个积分</option>
                        <option value="3">3个积分</option>
                        <option value="4">4个积分</option>
                        <option value="5">5个积分</option>
                        <option value="6">6个积分</option>
                        <option value="7">7个积分</option>
                        <option value="8">8个积分</option>
                        <option value="9">9个积分</option>
                        <option value="10">10个积分</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="*">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    layui.use(['layer', 'form', 'layedit'], function () {
        let $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            layedit = layui.layedit;

        let id = [[${res.id}]];

        let index = layedit.build('content', {
            uploadImage: {
                url: '/res/uploadImage',
                type: 'post'
            }
        });

        // 监听提交
        form.on('submit(*)', function (data) {
            let content = layedit.getContent(index);
            if (content == "") {
                layer.msg("请输入资源描述！");
                return false;
            }
            $("#content").val(content);

            $.post("/admin/res/save", data.field, function (result) {
                if (result.success) {
                    let msg = id ? "修改成功！" : "添加成功！";
                    layer.alert(msg, function () {
                        history.back();
                    });
                } else {
                    $("#errorInfo").text(result.errorInfo);
                }
            }, "json");
            return false;
        });
    });
    /*]]>*/
</script>
</body>
</html>